package websocket

import (
	"fmt"
	"encoding/json"
	// "github.com/gogf/gf/v2/util/gconv"
)

const (
	Error = "error"
	Login = "login"
	Join  = "join"
	Quit  = "quit"
	IsApp = "is_app"
	Ping  = "ping"
)

// ProcessData 处理客户端数据
func ProcessData(client *Client, message []byte) {
	fmt.Printf("ProcessData: received raw message: %s\n", string(message))
	
	req := &request{}
	if err := json.Unmarshal(message, req); err != nil {
		fmt.Printf("ProcessData unmarshal error: %v\n", err)
		return
	}
	
	fmt.Printf("ProcessData: parsed event=%s, data=%+v\n", req.Event, req.Data)
	switch req.Event {
	case "login":
		LoginController(client, req)
	case "join":
		JoinController(client, req)
	case "quit":
		QuitController(client, req)
	case "ping":
		PingController(client)
	case "is_app":
		IsAppController(client)
	case "message":
		MessageController(client, req)
	// 新增的聊天方式
	case "private_message":
		PrivateMessageController(client, req)
	case "room_message":
		RoomMessageController(client, req)
	case "broadcast_message":
		BroadcastMessageController(client, req)
	case "client_message":
		ClientMessageController(client, req)
	default:
		fmt.Printf("Unknown event: %s\n", req.Event)
	}
}